/*
 * 文件名：UserConfigServiceImpl.java
 * 版权：
 * 描述：TODO
 * 修改人：zuo liubo
 * 修改时间：2013-3-27 下午2:52:14
 */
package com.scpii.api.service.user.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.scpii.api.domain.auth.UserConfigs;
import com.scpii.api.persistence.auth.UserConfigsMapper;
import com.scpii.api.service.user.UserConfigService;

/**
 * @description TODO
 * @author zuo liubo
 * @date 2013-3-27
 */
@Service("userConfigService")
public class UserConfigServiceImpl implements UserConfigService {

	@Resource
	private UserConfigsMapper userConfigsMapper;

	@Override
	public boolean updatePushSetting(UserConfigs userConfigs) {
		if(userConfigs.getAcceptStartTime() > userConfigs.getAcceptEndTime()){
			userConfigs.setAcceptEndTime(23L);
		}
		
		List<UserConfigs> list = userConfigsMapper.selectUserConfigsByUserId(userConfigs.getUserId());
		if(list.size() == 0){
			return  userConfigsMapper.insert(userConfigs) > 0;
		}
		int affectRow = userConfigsMapper.updatePushSetting(userConfigs);
		return affectRow > 0 ;
	}

	@Override
	public UserConfigs selectUserConfigs(Long userId) {
		List<UserConfigs> list = userConfigsMapper.selectUserConfigsByUserId(userId);
		if(list.size() >0 ){
			return list.get(0);
		}
		UserConfigs uc = new UserConfigs();
		uc.setAcceptEndTime(23L);
		uc.setAcceptStartTime(0L);
		uc.setIsAccept(1L);
		uc.setUserId(userId);
		return uc;
	}
}
